package com.zzyl.common.qianfan;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.validation.constraints.Size;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2025/5/22 15:13
 * @Version 1.0
 */
@Component
@Slf4j
public class BaiduQianFanAi {

    @Value("${qianfan.key}")
    private String key;

    @Value("${qianfan.secret}")
    private String secret;
    @Value("${qianfan.model}")
    private String model;

    public String chatToQianfan(String prompt){
        log.info("开始请求千帆大模型，提示词为：{}",prompt);
        Qianfan qianfan = new Qianfan(key, secret);

        ChatResponse response = qianfan.chatCompletion().addMessage("user", prompt)
                .model(model)
                .temperature(0.8)
                .maxOutputTokens(2000)
                .responseFormat("json_object")
                .execute();
        log.info("千帆模型返回：{}",response.getResult());
        return response.getResult();
    }
}